package location.cn.org.wias.wifiscan;

import android.util.Log;

import java.io.IOException;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class HttpPost {


    private static OkHttpClient okHttpClient;
    private static MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    public static OkHttpClient getOkHttpClient() {
        if(okHttpClient == null) {
            okHttpClient = new OkHttpClient();
        }
        return  okHttpClient;
    }

    public static void Post(String url, String json) throws IOException{
        Log.e("Post", json);
        RequestBody body = RequestBody.create(JSON, json);
        Request request = new Request.Builder().url(url).post(body).build();
        Response response = getOkHttpClient().newCall(request).execute();
        if(response.isSuccessful()) {
           // Log.e("Post", response.body().toString());
        }
    }
}
